package com.mythread;

import java.util.concurrent.*;

/**
 * @ClassName ThreadTest
 * @Description
 * @Author xinggh
 * @Date 2020/8/15 23:50
 * @Version 1.0
 **/
public class ThreadTest {

    private static ExecutorService executorService = Executors.newFixedThreadPool(5);

    public static void main(String[] args) {
        MyTask myTask = new MyTask();
        FutureTask<Integer> futureTask = new FutureTask(myTask);
        executorService.submit(futureTask);
        try {
            Integer o = futureTask.get();
            System.out.println(o);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }

    public static class MyTask implements Callable<Integer> {


        @Override
        public Integer call() throws Exception {
            int sum = 0;
            for (int i = 0; i < 5; i++) {
                sum += i;
            }
            return sum;
        }
    }
}
